package red.book._1._2;

import edu.princeton.cs.algs4.Point2D;

/**
 * Write a Point2D client that takes an integer value N from the command line,
generates N random points in the unit square, and computes the distance separating
the closest pair of points.
 * @author wangbingwu
 *
 */
public class Ex01 {
	public static void main(String[] args) {
		int N = 10;
		Point2D[] points = new Point2D[N];
		
		for (int i = 0; i < N; i++) {
			points[i] = new Point2D(Math.random(), Math.random());
			points[i].draw();
		}
		
		if(N > 1) {
			double min = points[0].distanceTo(points[1]);
			
			for(int i = 0; i < N -1; i++) {
				for(int j =i + 1; j < N; j++) {
					if(points[i].distanceTo(points[j]) < min) {
						min = points[i].distanceTo(points[j]);
					}
				}
			}
			
			System.out.println(min);
		}
	}
}
